<?php

class WorkshopController extends GxController {

    public function actionindex() {
        $cs = Yii::app()->clientScript;
        $cs->scriptMap = array('jquery-1.11.0.min.js' => false,);
        $allClassCourseInfo = array();
        if($this->getUniqueId()!=$_GET['name']){
            throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));exit;
        }
        if (isset($_GET['name']) && $_GET['name'] == 'course') {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $allClassCourseInfo = runningCurrentCoursesByUser('', '', $_GET);
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
                $allClassCourseInfo = runningCurrentCoursesByUser('', '', $_GET);
                usort($allClassCourseInfo, 'date_compare');
            }
        } elseif (isset($_GET['name']) && ($_GET['name'] == 'workshop' OR $_GET['name'] == 'curatedclasses')) {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $allClassCourseInfo = literalEndingTommorow('', '', $_GET);
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
               $curatedArray=(!empty($_GET))?array('type' => 'workshop'):$_GET;                
                $allClassCourseInfo = literalEndingTommorow('', '', $curatedArray);
            }
        } else {
            $curatedArray = array('type' => 'workshop');
            $classDetails = literalEndingTommorow('', '', $curatedArray);
            $classDetails = array_map('unserialize', array_unique(array_map('serialize', $classDetails)));
            $allClassCourseInfo = $classDetails;
            usort($allClassCourseInfo, 'date_compare');
        }


        $dataProvider = new CArrayDataProvider($allClassCourseInfo, array(
                    'sort' => array(
                        'attributes' => array(
                            'start_date',
                        ),
                    ),
                    'pagination' => array(
                        'pageSize' => 9,
                    ),
                ));


        $this->render('//classes/_workshopRender', array('dataProvider' => $dataProvider));
    }

}